package com.zhang.sharding.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhang.sharding.entity.GlobalEventLog;
import com.zhang.sharding.mapper.GlobalEventLogMapper;
import com.zhang.sharding.service.GlobalEventLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @author ThinkPad
 * @version 1.0
 * @description: TODO
 * @date 2024/8/6 15:29
 */
@Service
public class GlobalEventLogServiceImpl implements GlobalEventLogService {

    @Resource
    private GlobalEventLogMapper globalEventLogMapper;

    private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy_MM");

    @Override
    @DS("sharding")
    public void insertLog(GlobalEventLog globalEventLog) {
        GlobalEventLog log = new GlobalEventLog();
//        log.setId(System.currentTimeMillis());
        log.setSeqNo(globalEventLog.getSeqNo());
        log.setErrorLog(globalEventLog.getErrorLog());
        log.setAcceptTime(globalEventLog.getAcceptTime());
        log.setFinishTime(globalEventLog.getFinishTime());
        globalEventLogMapper.insert(log);
    }

    @Override
    @DS("sharding")
    public List<GlobalEventLog> getAllLogs() {
        QueryWrapper<GlobalEventLog> queryWrapper = new QueryWrapper<>();
        return globalEventLogMapper.selectList(queryWrapper);
    }


}
